# -*- coding: utf-8 -*-
import time
import json
from MQTTConnector import MQTTConnector
from threading import Thread

if __name__ == "__main__":
    """Application entrance"""
    mqttConn = MQTTConnector(
        MQTTConnector.CLIENT_ID_CARLA, MQTTConnector.TASK_TOPIC_VCTL, MQTTConnector.TASK_TOPIC_CARLA, useTLS=True)
    Thread(target=lambda: mqttConn.startConnector("192.168.31.13", 1885), daemon=True).start()
    # Thread(target=lambda: mqttConn.startConnector("cs.safeiov.cn", 30024), daemon=True).start()
    
    # msgDict = {"cmd": "swing", "angel": "300", "arg2": "value2"}
    msgDict = {"cmd": "running", "angel": "0", "steer_speed": "80", "acc": "28", "gear": "r"}
    msgJsonStr = json.dumps(msgDict, ensure_ascii=False)
    time.sleep(1)
    while True:
        mqttConn.sendMsg("info to send")
        mqttConn.sendMsgDict(msgDict)
        time.sleep(1)
    mqttConn.sendMsgJsonStr(msgJsonStr)
    print("test over.!")
